<?php
#基础函数
include_once('_path.php');

#通用函数
include_once(_CONST_LOCAL_INCLUDE_PATH."common.php");

#db
include_once(_CONST_LOCAL_INCLUDE_PATH."database.class.php");
$database = new Database($db_vars);

#权限
if (!is_logined()) {
header("Location:"._CONST_WEB_URL."login-personal.html");
exit;
}

$uid = $_SESSION['user_id'];

$action = trim($_GET['action']);
$id = trim($_REQUEST['id']) + 0;
	$quote['id'] = string_sql($id);

if ($id > 0) {
	$sql = "SELECT * FROM members_message WHERE id=$id";
	$_file = $database->queryFirst($sql);
	if (!$_file['id']) {
            header("Location:p-feedback.php");
            exit;
	}
}
#如果是添加操作
if ($action == "message.do") {
    $content = trim($_REQUEST['content']);
    $quote['content'] = string_sql($content);
    $quote['dateline'] = string_sql(time());
    $sql = "INSERT INTO members_message ( uid, content, dateline) VALUES ($uid,".$quote['content'].", ".$quote['dateline'].");";
    $database->execute($sql);
}  else if ($action == "delete.do" && $id > 0) {
        $database->execute("DELETE FROM members_message WHERE id = $id OR rid=$id");
}

$sql = "SELECT * FROM members_message WHERE uid=".$uid." AND rid=0";
$rsc = $database->queryArray($sql);
?>
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="UTF-8">
	<title>用户中心-Haiersi•GL-海尔斯管历健康服务网</title>
	<link href="../media/css/reset.css" rel="stylesheet" type="text/css"/>
	<link href="../media/css/base.css" rel="stylesheet" type="text/css"/>
	<script type="text/javascript" src="../media/js/jquery-1.4.2.min.js"></script>
         <script type="text/javascript" src="../media/js/jquery.validate.min.js"></script>
        <script type="text/javascript">
jQuery.noConflict();
jQuery(function($) {
  $('#form').validate({
  });
});
</script>
</head>
<body id="uc">
<div class="wrapper">
	<div class="header clearfix">
		<a  class="logo fl" href="../index.html"><h1>Hesgl</h1></a>
		<ul class="nav fr clearfix">
			<li class="cur"><a href="../index.html">首页</a></li>
			<li><a href="../about-us.html">关于我们</a></li>
			<li><a href="../services.html">我们的服务</a></li>
			<li><a href="../approach.html">我们的方法</a></li>
			<li><a href="../health.html">企业健康管理</a></li>
			<li><a href="../news.html">新闻</a></li>
			<li class="last"><a href="../contacts.html">联系我们</a></li>
		</ul>
	</div>

    <div class="content clearfix">
    	<div class="user-info">欢迎<em><?=$_SESSION['name']?></em> ［<a href="../logout.php">退出登录</a>］</div>
        <div class="main">
            <div class="traininc-nav-list">
        		<ul>
        			<li><a href="p-home.html">基本信息</a></li>
        			<li><a href="p-file.html">文件上传</a></li>
        			<li class="selected"><a href="p-feedback.html">健康咨询</a></li>
        		</ul>
        	</div>
        	<div class="box-con">
	         <form action="p-feedback.php?action=message.do" method="post" id="form" name="form" >
                    <table class="table-input">
	        		<tr>
	        			<td class="title">咨询问题</td>
                                        <td><input type="text" size="50" name="content" id="content" class="required"></td>
	        		</tr>
	        		<tr>
	        			<td class="title"> </td>
	        			<td><input type="submit" name="" value="提交" class="btnA" /><input type="reset" name="" value="取消" class="btnB" /></td>
	        		</tr>
	        	</table>
                 </form>
	        	<br />
	        	<h3>历史咨询</h3>
        		<table class="table-blue">
        			<thead>
        				<tr>
        					<th>编号</th>
        					<th>咨询内容</th>
        					<th>回复</th>
        					<th>咨询日期</th>
        					<th>操作</th>
        				</tr>
        			</thead>
        			<tbody>
                                       <?
                                        for($i=0;$i<sizeof($rsc);$i++){
                                        $r = $rsc[$i];
                                        $j = 1;
                                        ?>
                                        <tr <?=iif($j%2==0, 'class="odd"')?>>
                                                        <td><?=$r['id']?></td>
							<td><?=$r['content']?></td>
                                                        <td>
                                        <?php
                                        $pr = array();
                                        $pr = $database->queryFirst("SELECT content,dateline FROM members_message WHERE rid=".$r['id']);
                                               if($pr['content']){
                                        ?>
                                        <?=$pr['content']?><br />
                                        <?=date(_CONST_DATE_FORMAT.' '._CONST_TIME_FORMAT,$pr['dateline'])?>
                                        <?php
                                               }
                                        ?>
                                                        </td>
                                        <td><?=date(_CONST_DATE_FORMAT.' '._CONST_TIME_FORMAT,$r['dateline'])?></td>
                                        <td><a href="p-feedback.php?action=delete.do&id=<?=$r['id'] ?>">删除</a></td>
					</tr>
                                        <?
                                        $j++;
                                        }
                                        ?>
        			</tbody>
        		</table>

        	</div>
        </div>

    </div>
	<div class="footer">
	    <p class="copyright">Copyright © 2011 Hesgl.com All Rights Reserved</p>
	</div>
</div>
</body>
</html>
